package com.material.c2c.user.service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.cpt.framework.core.OperationResult;
import com.material.c2c.core.UUIDGenerator;
import com.material.c2c.user.dao.AdminDao;
import com.material.c2c.user.entity.ADMIN;

@Service
public class AdminServiceImpl implements AdminService{
	@Resource
	private AdminDao adminDao;
	
	@Transactional
	@Override
	public OperationResult add(ADMIN admin) {
		admin.setId(UUIDGenerator.generateUUIDStr());
		admin = adminDao.add(admin);
		if(admin == null) {
			return OperationResult.failed("添加失败！");
		}
		return OperationResult.SUCCEED;
	}
	@Transactional
	@Override
	public OperationResult update(ADMIN	admin) {
		admin = adminDao.update(admin);
		if(admin == null) {
			return OperationResult.failed("添加失败！");
		}
		return OperationResult.SUCCEED;
	}
	@Override
	public Page<ADMIN>	search(String key ,Pageable page) {
		return adminDao.findAll(page);
	}
	@Transactional
	@Override
	public OperationResult delete(String id) {
		adminDao.delete(id);
		return OperationResult.SUCCEED;
	}
	@Override
	public ADMIN getOne(String id) {
		return adminDao.getOne(id);
	}
	@Override
	public ADMIN getByGlyxm(String name) {
	  return adminDao.findByGlyxm(name);
	}
}
